package states 
{
	import flash.geom.Point;
	import model.MGameboard;
	import statemachine.IState;
	import statemachine.IStateObject;
	import statemachine.IStatesFactory;
	import states.*;
	/**
	 * ...
	 * @author vkozhaev
	 */
	public class StatesFactory implements IStatesFactory
	{
		private var _mGameboard:MGameboard;
		public function StatesFactory(_mGameboard:MGameboard) 
		{
			this._mGameboard = _mGameboard;
		}
		
		
		public function makeNewState(stateObject:IStateObject,newStateName:String):IState {
			switch(newStateName) {
				case FindResourceState.NAME:			
					
					var dx:Number = Math.round(1 - 2 * Math.random());
					var dy:Number = Math.round(1 - 2 * Math.random());
					
					return new FindResourceState(stateObject, new Point(dx, dy));
				
				case NullEnergyState.NAME:
					trace("Null energy state");
					return new NullEnergyState(stateObject);
					
				case GetResourcesState.NAME:
					return new GetResourcesState(stateObject, _mGameboard);
					
				case GoToEnergyStationState.NAME:
					return new GoToEnergyStationState(stateObject, _mGameboard.serviceStation.cellCoords);
				case ProcessServiceState.NAME:
					return new ProcessServiceState(stateObject);
			}
			
			throw new Error("Haven't state with this name"+newStateName);
		}
		
	}

}